﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands.一级科室;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;
using System.ComponentModel;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers.一级科室
{
    public class DeleteDepartmentCommandHandler : IRequestHandler<DeleteDepartmentCommand, APIResult<int>>
    {
        private readonly IBaseRespository<DepartmentModel> depRep;

        public DeleteDepartmentCommandHandler(IBaseRespository<DepartmentModel> depRep)
        {
            this.depRep = depRep;
        }
        public async Task<APIResult<int>> Handle(DeleteDepartmentCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code=ResultCode.删除成功;
            result.Message=ResultCode.删除成功.ToString();

            var res = depRep.GetAll().FirstOrDefault(x=>x.DepartmentId==request.DepartmentId);
            res.IsDeleted=true;
            await depRep.UpdateAsync(res);

            return await Task.FromResult(result);   
        }
    }
}
